<script type="text/javascript">
    $(document).ready(function() {
        // date picker
        $(".tanggal,.tanggal-selesai").datepicker({
            yearRange: '-1:+1',
            target: 'tanggal',
            changeMonth: true,
            changeYear: true,
            showOn: 'both',
            buttonImage: '{$BASEURL}/resource/doc/images/icon/calendar.gif',
            buttonImageOnly: true,
            dateFormat: 'yy-mm-dd'
        });
        
        $('#services_parts,#services_biaya').autoNumeric({
            aSep: '.', aDec: ',', vMax: "999999999999999", vMin: "0"
        });
        
        // form cari data barang
        $('#form-cari').dialog({
            autoOpen: false,
            modal: true,
            title: "Pencarian Data Barang",
            draggable: false,
            width: 900,
            height: 550
        });

        /*
         * Event pencarian
         */

        // trigger cari data barang
        $('#get_barang').click(function() {
            // tampilkan form cari
            $('#form-cari').dialog('open');
            $('#data').html('<p style="font-size: 11px; color: #666;">Masukkan nomor inventaris dan atau nama barang diatas!</p>');
            return false;
        });

        //paging
        function paging(offset, id) {
            //paging
//            $('.offset').click(function() {
            // ajax loader
            $("#ajax-loader").ajaxStart(function() {
                $('#data').hide();
                $(this).show();
            });
            $("#ajax-loader").ajaxStop(function() {
                $(this).hide();
                $('#data').show();
            });
            // --------------
            var barang_noinventaris = $('#barang_noinventaris').val();
            var barang_nama = $('#barang_nama').val();
            $.ajax({
                type: 'POST',
                data: 'barang_noinventaris=' + barang_noinventaris + '&barang_nama='+barang_nama+'&offset=' + offset,
                url: '{$config->site_url("inventarisasi/service/cari_barang/")}',
                success: function(result) {
                    $('#data').html(result);
                    //paging
                    $('.offset').removeClass("active");
                    $('#'+id).addClass("active");
                    //pilih
                    $('.button-edit').click(function() {
                        //
                        var data_barang = $(this).attr('title');
                        var kode_barang = $(this).attr('lang');
                        // put result
                         $('#barang_data').val(data_barang);
                         $('#barang_id').val(kode_barang);
                        // close dialog
                        $('#form-cari').dialog('close');
                        // --
                        return false;
                    });
                    //function paging
                    $('.offset').click(function() {
                        var id = $(this).attr("id");
                        var offset = $(this).attr('id');
                        paging(offset, id);
                    });
                }
            });
            return false;
//            });
        }

        // cari data barang pada database
        $('#tombol-cari').click(function() {
            // ajax loader
            $("#ajax-loader").ajaxStart(function() {
                $('#data').hide();
                $(this).show();
            });
            $("#ajax-loader").ajaxStop(function() {
                $(this).hide();
                $('#data').show();
            });
            // --------------
            var barang_noinventaris = $('#barang_noinventaris').val();
            var barang_nama = $('#barang_nama').val();
            $.ajax({
                type: 'POST',
                data: 'barang_noinventaris=' + barang_noinventaris + '&barang_nama=' + barang_nama,
                url: '{$config->site_url("inventarisasi/service/cari_barang/")}',
                success: function(result) {
                    $('#data').html(result);
                    //class active paging
                    $('#0').addClass("active");
                    //pilih
                    $('.button-edit').click(function() {
                        var data_barang = $(this).attr('title');
                        var kode_barang = $(this).attr('lang');
                        // put result
                        $('#barang_data').val(data_barang);
                         $('#barang_id').val(kode_barang);
                        // close dialog
                        $('#form-cari').dialog('close');
                        // --
                        return false;
                    });
                    //function paging
                    $('.offset').click(function() {
                        //class active paging
                        var id = $(this).attr("id");
                        var offset = $(this).attr('id');
                        paging(offset, id);
                    });
                }
            });
            return false;
        });
        
    });
</script>
<div class="breadcrum">
    <p>
        <a href="#">Inventarisasi</a>
        <span></span><a href="{$config->site_url('inventarisasi/service')}">Service</a>
        <span></span><small>Edit Data</small>
    </p>
    <div class="clear"></div>
</div>  
<div class="sub-content">  
    <div class="navigation">  
        <div class="navigation-button">
            <ul>
                <li><a href="{$config->site_url('inventarisasi/service/add')}"><img alt="" src="{$BASEURL}/resource/doc/images/icon/add-icon.png">Tambah Data</a></li>
                <li><a href="{$config->site_url('inventarisasi/service')}"><img alt="" src="{$BASEURL}/resource/doc/images/icon/icon.notes.blue.png">Daftar Data</a></li> 
            </ul>
            <div class="clear"></div>
        </div>
    </div> 
    <!-- notification template -->
    {include file="base/templates/notification.html"}
    <!-- end of notification template--> 
    <form action="{$config->site_url('inventarisasi/service/edit_process')}" method="post" enctype="multipart/form-data">
        <input type="hidden" name="services_id" value="{$result.services_id|default:''}" />
        <input type="hidden" name="services_file" value="{$result.services_file|default:''}" />
        <table width="100%" class="table-input">
            <tbody>
                <tr class="headrow">
                    <th colspan="2">Edit Service</th>
                </tr>
                <tr>
                    <td width="15%">Barang</td>
                    <td width="85%">
                        <input type="hidden" name="barang_id" id="barang_id" value="{$result.barang_id|default:''}">
                        <input type="text" size="50" name="barang_data" id="barang_data" value="{$result.barang_noinventaris|default:''} | {$result.barang_nama|default:''}" readonly="readonly">
                        <a title="{$result.services_id|default:''}" id="get_barang" href="#" class="button-edit" >Pilih Barang</a><small>* wajib diisi</small>
                    </td>  
                </tr>
                <tr>
                    <td width="15%">Deskripsi</td>
                    <td width="85%">
                        <input type="text" size="40" name="services_desc" value="{$result.services_desc|default:''}">
                        <small>* wajib diisi</small>
                    </td>  
                </tr>
                <tr>
                    <td>Tanggal Mulai</td>
                    <td>
                        <input class="tanggal" name="services_tgl" type="text" value="{$result.services_tgl|default:''}" size="10" maxlength="10" readonly="readonly" />
                        <small>* wajib diisi</small>
                    </td>  
                </tr> 
                <tr>
                    <td>Tanggal Selesai</td>
                    <td>
                        <input class="tanggal-selesai" name="services_tglselesai" type="text" value="{$result.services_tglselesai|default:''}" size="10" maxlength="10" readonly="readonly" />
                        <small>* wajib diisi</small>
                    </td>  
                </tr>  
                <tr>
                    <td>Biaya Sparepart</td>
                    <td>
                        <input style="text-align: right;font-size:16pt;color: red;font-weight: bold;" type="text" size="15" id="services_parts" value="{$result.services_parts|default:''}" name="services_parts">
                        <small>* wajib diisi</small>
                    </td>
                </tr>
                <tr>
                    <td>Biaya Service</td>
                    <td>
                        <input style="text-align: right;font-size:16pt;color: red;font-weight: bold;" type="text" size="15" id="services_biaya" value="{$result.services_biaya|default:''}" name="services_biaya">
                        <small>* wajib diisi</small>
                    </td>
                </tr>
                <tr>
                    <td>Upload File</td>
                    <td><input name="services_file" type="file" />
                    <small>* hanya format pdf</small></td>  
                </tr> 
                <tr>
                    <td>Keterangan</td>
                    <td><textarea name="services_keterangan" rows="5" cols="50">{$result.services_keterangan|default:''}</textarea></td>  
                </tr>
                <tr>
                    <td>Status</td>
                    <td>
                        <select name="services_status" id="services_status" style="width:200px;" class ="select2" >
                            <option value=""></option>
                            <option value="belum" {if {$result.services_status|default:''} eq 'belum'}selected="selected"{/if}>Belum Selesai</option>
                            <option value="selesai" {if {$result.services_status|default:''} eq 'selesai'}selected="selected"{/if}>Selesai</option>
                        </select>
                        <small>* wajib diisi</small> 
                    </td>
                </tr>
                <tr class="submit-box">
                    <td colspan="4">
                        <input type="submit" class="edit-button" value="Simpan" name="save[insert]">
                        <input type="reset" class="edit-button" value="Reset" name="save[reset]">
                    </td>
                </tr>
            </tbody>
        </table>
    </form> 
</div>
<div id="form-cari" style="display: none;">
    <div class="search-box">
        <form action="#" method="post">
            <table class="table-search" width="100%">
                <tr>
                    <th width="15%">No. Inventaris</th>
                    <td width="25%">
                        <input name="barang_noinventaris" type="text" value="" size="30" id="barang_noinventaris" />
                    </td>
                    <th width="15%">Nama Barang</th>
                    <td width="55%">
                        <input name="barang_nama" type="text" value="" size="30" id="barang_nama" />
                        <input class="button blue" name="save[filter]" type="submit" value="Cari" id="tombol-cari" />
                    </td>
                </tr>
            </table>
        </form>
    </div>
    <div id="data"></div>
    <div id="ajax-loader" style="display: none;">
        <div class="result">
            <p align="center">
                <img src="{$BASEURL}resource/doc/images/icon/ajax-loader.gif" alt="" />
                <br />
                <small>Please Wait</small>
            </p>
        </div>
    </div>
</div>